using UnityEngine;
class RenderTexutreUtils
{
    public static Texture2D ToTexture(RenderTexture rt)
    {
        RenderTexture.active = rt;
        Texture2D texture = new Texture2D(rt.width,rt.height,TextureFormat.RGBAFloat,true);
        texture.ReadPixels(new Rect(0,0,rt.width,rt.height),0,0);
        texture.Apply();
        RenderTexture.active = null;

        texture.wrapMode = rt.wrapMode;
        return texture;
    }

    
    public static Texture2D RT2Tex(RenderTexture rt,int targetSize)
    {
        if(rt==null)
        return null;
        
        RenderTexture tempRT = new RenderTexture(targetSize,targetSize,0);
        tempRT.wrapMode = rt.wrapMode;
        Graphics.Blit(rt,tempRT);

        RenderTexture.active = tempRT;
        Texture2D texture = new Texture2D(tempRT.width,tempRT.height,TextureFormat.RGBAFloat,true);
        texture.ReadPixels(new Rect(0,0,tempRT.width,tempRT.height),0,0);
        texture.wrapMode = rt.wrapMode;
        texture.Apply();
        RenderTexture.active = null;

        tempRT.Release();

        return texture;
    }
}